package tt.langchain4j.store;

import dev.langchain4j.data.segment.TextSegment;
import dev.langchain4j.store.embedding.EmbeddingStore;
import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import tt.langchain4j.Constants;
import tt.langchain4j.core.BufferSupplier;

import java.util.function.Supplier;

public enum EmbeddingStores {



    REDISSON_0(()->new RedissonEmbeddingStore(getRedissonClient(0))),
    REDISSON_1(()->new RedissonEmbeddingStore(getRedissonClient(1))),
    REDISSON_2(()->new RedissonEmbeddingStore(getRedissonClient(2))),
    REDISSON_3(()->new RedissonEmbeddingStore(getRedissonClient(3))),
    REDISSON_4(()->new RedissonEmbeddingStore(getRedissonClient(4))),




    ;


    public static final EmbeddingStores DEFAULT = REDISSON_0;


    private final BufferSupplier<EmbeddingStore<TextSegment>> embeddingStore;

    EmbeddingStores(Supplier<EmbeddingStore<TextSegment>> embeddingStore) {
        this.embeddingStore = new BufferSupplier<>(embeddingStore);
    }


    public EmbeddingStore<TextSegment> embeddingStore() {
        return embeddingStore.get();
    }

    private static RedissonClient getRedissonClient(int databaseNo) {
        Config config = new Config();
        config.useSingleServer().setAddress(Constants.REDIS_URL);
        config.useSingleServer().setDatabase(databaseNo);
        return Redisson.create(config);
    }




}
